package com.lahuan.demo.controller;


import org.springframework.web.bind.annotation.*;

import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import lombok.RequiredArgsConstructor;
import com.lahuan.common.Result;
import com.lahuan.demo.service.TestStudentService;
import com.lahuan.demo.entity.TestStudent;
import javax.validation.Valid;

/**
 * <p>
 * 学生 控制器
 * </p>
 * @author lahuan
 * @since 2021-12-04
 */
@RequiredArgsConstructor
@RestController
@Slf4j
@Api(value = "test_student", tags = "学生接口")
@RequestMapping("/demo/testStudent")
public class TestStudentController {

    private final TestStudentService testStudentService;

    @ApiOperation(value = "获取学生分页列表",notes="获取学生分页列表")
    @GetMapping("")
    public  Result<Page<TestStudent>> testStudentList(Page< TestStudent> page, TestStudent query) {
        return Result.ok(testStudentService.page(page, Wrappers.query(query)));
    }

    @ApiOperation(value = "根据id获取学生",notes="根据id获取学生")
    @ApiImplicitParam(name = "id", value = "学生id", required = true, dataType = "Long ")
    @GetMapping("/{id}")
    public Result<TestStudent> testStudentGetById(@PathVariable Long id) {
        return Result.ok(testStudentService.getById(id));
    }

    @ApiOperation(value = "添加学生",notes="新增学生")
    @PostMapping("")
    public Result<Boolean> testStudentSave(@RequestBody @Valid  TestStudent testStudent) {
        return Result.ok(testStudentService.save(testStudent));
    }

    @ApiOperation(value = "修改学生",notes="根据id修改学生")
    @PutMapping("/{id}")
    public Result<Boolean> testStudentUpdate(@RequestBody @Valid  TestStudent testStudent, @PathVariable Long id) {
        testStudent.setId(id);
        return Result.ok(testStudentService.updateById(testStudent));
    }

    @ApiOperation(value = "删除学生",notes="根据id删除学生")
    @ApiImplicitParam(name = "id", value = "学生id", required = true, dataType = "Long ")
    @DeleteMapping("/{id}")
    public Result<Boolean> testStudentDelete(@PathVariable Long id) {
        return Result.ok(testStudentService.removeById(id));
    }


}
